#include <stdio.h> //for printf
#include <stdlib.h> //for exit
#include "stack.h"

struct myDataNode {
    char name[10];
    int age;
};
typedef struct myDataNode myNode_t;


int main() {
    stack_t stackA;

    if (init(&stackA, 100) == STACK_FAIL) {
        printf("initial stack error\n");
        exit(1);
    }

    //push
    for (int i = 1; i<5; i++) {
        myNode_t *node = (myNode_t *) malloc(sizeof(myNode_t));
        sprintf(node->name, "robert_%d", i);
        node->age = 15+i;

        if (push(&stackA, (void *)node) != STACK_OK) {
            printf("push error %d\n", i);
        }
        printf("push %d into stack\n", i);
    }

    //pop

    while(!isEmpty(&stackA)) {
        myNode_t *x;
        if (pop(&stackA, (void **) &x)!= STACK_OK) {
            printf("pop error\n");
        } else {
            printf("pop %s from stack\n", x->name);
            free(x);
        }
    }


}